package src.E_Thread;

// 线程的优先级（ps：优先级越高被cpu优先调用的机率会高，但并不是一定会被优先调度，只是概率比其他优先级底的高，看cpu心情）
public class E13_ThreadPriority {
    public static void main(String[] args) {
        System.out.println(Thread.currentThread().getName()+"--->"+Thread.currentThread().getPriority());
        MyPriority priority = new MyPriority();
        Thread thread1 = new Thread(priority);
        Thread thread2 = new Thread(priority);
        Thread thread3 = new Thread(priority);
        Thread thread4 = new Thread(priority);
        Thread thread5 = new Thread(priority);
        // 设置优先级，再启动
        thread1.start(); // Thread.NORM_PRIORITY 不设置默认为5，main主线程也为5

        thread2.setPriority(Thread.MIN_PRIORITY); // 优先级最小为1
        thread2.start();

        thread3.setPriority(Thread.MAX_PRIORITY); // 优先级最大为10
        thread3.start();

        thread4.setPriority(3);
        thread4.start();

        thread5.setPriority(7);
        thread5.start();
    }
}

class MyPriority implements Runnable{
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"--->"+Thread.currentThread().getPriority());
    }
}
